# -*- coding: utf-8 -*-
# @Time      : 2024/5/13 13:40
# @Author    : 未命名
# @File      : sql.py
# @Software  : PyCharm


import sqlite3

# 创建数据库连接

#1、创建数据库连接
conn = sqlite3.connect('test.db')  #创建数据库对象
print("成功打开数据库")

#2.创建数据表
# c = conn.cursor()    #设计数据库游标
# sql = '''
#       CREATE TABLE company
#          (
#             id int PRIMARY KEY not null ,
#             name text not null ,
#             age int not null ,
#             address char(50) ,
#             salary real
#          );
# '''
#
#
# c.execute(sql)     #执行sql语句
# conn.commit()      #提交数据库操作
# conn.close()       #关闭数据库连接
# print("成功建功数据表")

#3插入数据
# c = conn.cursor()
# sql = '''
#       insert into company (id ,name,age,address,salary)
#       values (1,'张三',12,'鹤岗',123);
# '''
# c.execute(sql)
# conn.commit()
# conn.close()

#4查看数据

# c= conn.cursor()
# sql = '''
#       select * from company;
# '''
# result = c.execute(sql)
#
# print(result)
# for item in result:
#     print("id = ", item[0])
#     print("name = ", item[1])
#     print("age = ", item[2])
#     print("address = ", item[3])
#     print("salary = ", item[4])
# print(result)
# conn.close()
# print("查询成功")











